package at.fhooe.stefanirndorfer.event;

import at.fhooe.stefanirndorfer.update.Updateable;


public class EventManager implements Updateable {

	private DispatchStrategy m_dispatchStrategy;
	private ListenerStrategy m_listenerStrategy;

	public EventManager(DispatchStrategy dispatchStrategy,
			ListenerStrategy listenerStrategy) {
		m_listenerStrategy = listenerStrategy;
		m_dispatchStrategy = dispatchStrategy;
		m_dispatchStrategy.setListenerStrategy(m_listenerStrategy);
	}

	@Override
	public synchronized void update(double dt) {
		m_dispatchStrategy.update(dt);
	}

	public synchronized <T extends Event<?>> void dispatchEvent(T event) {
		m_dispatchStrategy.dispatchEvent(event);
	}

	public synchronized <T extends EventListener> void removeListener(
			T eventListener, Class<? extends Event<T>> eventType) {
		m_listenerStrategy.removeListener(eventListener, eventType);
	}

	public synchronized <T extends EventListener> void addListener(
			T eventListener, Class<? extends Event<T>> type) {
		m_listenerStrategy.addListener(eventListener, type);
	}

	public void removeAllListeners() {
		m_listenerStrategy.removeAllListeners();
	}

	public void setListenerStrategy(ListenerStrategy listenerStrategy) {
		m_listenerStrategy = listenerStrategy;
		m_dispatchStrategy.setListenerStrategy(m_listenerStrategy);
	}

	public void setDispatchStrategy(DispatchStrategy dispatchStrategy) {
		m_dispatchStrategy = dispatchStrategy;
		m_dispatchStrategy.setListenerStrategy(m_listenerStrategy);
	}

	public void clearEventsForDispatch() {
		m_dispatchStrategy.clearEventsForDispatch();
	}
}
